<template>
  <div class="app-container-flex">
    <NewFullScreen v-model="showDialog" :title="title">
      <template v-slot:full-button>
        <el-button @click="save()">保存</el-button>
      </template>
      <div class="model-panel">
        <div class="model-panel-title">
          <p>{{ $t('basic_information') }}</p>
        </div>
        <div class="model-panel-body">
          <!-- form -->
          <page-form
            class="paddingBox order-model-formBox flex_wrap_start_start"
            v-model:ref-obj="formInfo.ref"
            :disabled="formInfo.disabled"
            :data="formInfo.data"
            :field-list="formInfo.fieldList"
            :rules="formInfo.rules"
            :label-width="formInfo.labelWidth"
          >
            <template v-slot:form-preAssetName>
              <el-input
                v-model="formInfo.data.preAssetName"
                type="input"
                :disabled="true"
                :class="id ? '' : 'not-mongolia'"
                placeholder="请选择资产"
              >
                <template #append>
                  <el-icon v-if="!id" @click="openAssetWindow"
                    ><MoreFilled
                  /></el-icon>
                </template>
                <!-- <i
                  slot="append"
                  :class="
                    id
                      ? 'el-icon-more i_more i-more-disabled'
                      : 'el-icon-more i_more i-more'
                  "
                  @click="openAssetWindow"
                ></i> -->
              </el-input>
            </template>
            <template v-slot:form-nextExecuteDate>
              <el-date-picker
                v-model="formInfo.data.nextExecuteDate"
                type="datetime"
                value-format="YYYY-MM-DD HH:mm:ss"
                placeholder="选择日期时间"
              >
              </el-date-picker>
            </template>
            <template v-slot:form-maintenancePrincipalValue>
              <el-input
                v-model="formInfo.data.maintenancePrincipalValue"
                type="input"
                :disabled="true"
                class="not-mongolia"
                placeholder="请选择养护负责人"
              >
                <template #append>
                  <el-icon @click="openUserWindow"><MoreFilled /></el-icon>
                </template>
              </el-input>
            </template>
            <template v-slot:form-remindTime>
              <el-input-number
                v-model="formInfo.data.remindTime"
                controls-position="right"
                :min="0"
                :max="999999999999999999"
                placeholder="请输入内容"
                :precision="1"
                style="width: 65%; display: inline-block"
              ></el-input-number>
              <select-model
                v-model.trim="formInfo.data.remind"
                typeCode="remind_time_type"
                style="width: 35%"
              />
            </template>
          </page-form>
        </div>
      </div>

      <div class="model-panel">
        <div class="model-panel-title">
          <p>养护项目</p>
        </div>
        <div class="model-panel-body">
          <!-- 条件栏 -->

          <NewPageFilter
            v-model:query="itemsFilterInfo.query"
            :filter-btn="itemsFilterInfo.list"
          >
            <template v-slot:filter-removeItem>
              <el-button
                :disabled="!itemsTableInfo.selections.length"
                @click="removeItem()"
                >删除项目</el-button
              >
            </template>
          </NewPageFilter>
          <div class="flex_full_item">
            <el-form
              ref="itemsTableForm"
              :model="itemsTableInfo"
              style="width: 100%"
            >
              <!-- 表格 -->
              <page-table
                :refresh="itemsTableInfo.refresh"
                :init-curpage="itemsTableInfo.initCurpage"
                v-model:data="itemsTableInfo.data"
                :api="itemsTableInfo.api"
                :query="itemsTableInfo.query"
                :pager="false"
                :tab-index="true"
                :field-list="itemsTableInfo.fieldList"
                :handle="itemsTableInfo.handle"
                :isDynamic="true"
                :row-class-name="tableRowClassName"
                @handleEvent="handleEventItems"
              >
                <template #col-maintenanceParts="scope">
                  <el-form-item
                    class="form-input"
                    :prop="`data.${scope.$index}.maintenanceParts`"
                    :rules="[
                      {
                        required: scope.$index > -1,
                        message: '请输入养护项目',
                        trigger: 'blur',
                      },
                    ]"
                  >
                    <el-input
                      v-model="scope.row.maintenanceParts"
                      maxlength="200"
                    >
                    </el-input>
                  </el-form-item>
                </template>
                <template #col-contentRequire="scope">
                  <el-form-item
                    class="form-input"
                    :prop="`data.${scope.$index}.contentRequire`"
                    :rules="[
                      {
                        required: scope.$index > -1,
                        message: '请输入养护内容与要求',
                        trigger: 'blur',
                      },
                    ]"
                  >
                    <el-input
                      v-model="scope.row.contentRequire"
                      maxlength="200"
                    >
                    </el-input>
                  </el-form-item>
                </template>
                <template #col-result="scope">
                  <radio-model
                    v-model.trim="scope.row.result"
                    type-code="appearance_quality"
                    class="form-input"
                  />
                </template>
                <template #col-remark="scope">
                  <el-form-item
                    class="form-input"
                    :prop="`data.${scope.$index}.remark`"
                  >
                    <el-input v-model="scope.row.remark" maxlength="200">
                    </el-input>
                  </el-form-item>
                </template>
              </page-table>
            </el-form>
          </div>
        </div>
      </div>
    </NewFullScreen>

    <!-- 养护负责人 -->
    <SelectUsers
      v-if="selectUserInfo.visible"
      v-model:show-dialog="selectUserInfo.visible"
      :api="getRrgUserList"
      :save-empty="true"
      :query="selectUserInfo.query"
      :check-box="false"
      :highlight-row="true"
      @callback="selectUserCallback"
    />
    <!--资产选择-->
    <Select-asset
      v-if="selectAssetInfo.visible"
      v-model:show-dialog="selectAssetInfo.visible"
      :highlight-row="true"
      :check-box="false"
      :table-key="selectAssetInfo.tableKey"
      :query="selectAssetInfo.query.queryMap"
      :query-params="selectAssetInfo.query.queryParams"
      @callback="callBackAsset"
    />
    <!-- 供应商 -->
    <select-supplier
      v-if="selectSupplierInfo.visible"
      v-model:show-dialog="selectSupplierInfo.visible"
      :query="selectSupplierInfo.query"
      :check-box="false"
      :save-empty="true"
      :highlight-row="true"
      :api="selectSupplierInfo.api"
      @callback="selectSupplierCallback"
    />
    <!-- 选择配件 -->
    <SelectAccessories
      v-if="accessoriesInfo.visible"
      v-model:show-dialog="accessoriesInfo.visible"
      :query="accessoriesInfo.query"
      :table-key="accessoriesInfo.tableKey"
      @callback="changeAccessories"
    />
    <SelectCustomizeTable
      v-if="selectCustomizeTableInfo.visible"
      v-model:visible="selectCustomizeTableInfo.visible"
      :api="selectCustomizeTableInfo.api"
      :query="selectCustomizeTableInfo.query"
      :tableKey="selectCustomizeTableInfo.tableKey"
      :defaultObj="selectCustomizeTableInfo.defaultObj"
      :checkBox="true"
      :highlightRow="false"
      title="选择养护模板"
      @callback="selectCustomizeTableCallback"
    />
  </div>
</template>

<script setup name="deviceMaintenanceTaskModify">
import PageForm from '@/components/PageForm/index'
import PageTable from '@/components/PageTable/index'
import { getSupplierPage } from '@/api/core'
import {
  updateByIdWhenStatusNotStart,
  createDeviceMaintenanceTask,
  getDeviceMaintenanceTaskById,
  getDeviceMaintenanceTaskProgramAll,
  getDeviceMaintenanceTaskAccessoriesCustomizeListAll,
} from '@/api/repair'
import {
  getDeviceMaintenanceTemplateCustomizeListPage,
  getDeviceTemplateListByIds,
} from '@/api/device.js'
import { getCustomizeSetting } from '@/api/customize'
import { getRrgUserList } from '@/api/base.js'
import SelectUsers from '@/components/SelectUsers/index'
import selectAsset from '@/components/SelectAsset/index'
import SelectSupplier from '@/components/SelectSupplier/index'
import SelectAccessories from '@/components/SelectAccessories/index'
import RadioModel from '@/components/ModelRadio'
import moment from 'moment'

import axios from 'axios'
import { ElMessage } from 'element-plus'

const { proxy } = getCurrentInstance()
const emit = defineEmits()
const props = defineProps(['visible', 'title', 'id'])

const action = ref(axios.defaults.baseURL + '/pub/uploadfile')
let formRefs = []
let validateRemind = (rule, value, callback) => {
  let num = formInfo.data.remindTime
  if (formInfo.data.remind == '1') {
    if (num < 5) {
      callback(new Error('输入的提醒分钟必须大于等于5！'))
    } else {
      callback()
    }
  } else if (formInfo.data.remind == '2' || formInfo.data.remind == '3') {
    if (num <= 0) {
      callback(new Error('输入的提醒小时或天必须大于0！'))
    } else {
      callback()
    }
  } else {
    callback()
  }
}
const formInfo = reactive({
  ref: null,
  data: {
    preAssetName: '',
    preAssetCode: '',
    remind: 1,
  },
  fieldList: [
    {
      label: '养护类型',
      value: 'type',
      type: 'select-model',
      code: 'device_maintenance_type',
      require: true,
      disabled: false,
    },
    {
      label: '资产',
      value: 'preAssetName',
      type: 'slot',
      required: true,
      disabled: false,
    },
    {
      label: '资产卡片号',
      value: 'assetCode',
      type: 'input',
      disabled: true,
    },
    {
      label: '使用部门',
      value: 'preUseDeptValue',
      type: 'input',
      disabled: true,
    },
    {
      label: '仓库',
      value: 'depotName',
      type: 'input',
      disabled: true,
    },
    {
      label: '计划执行日期',
      value: 'nextExecuteDate',
      type: 'slot',
      require: true,
    },
    {
      label: '养护负责人',
      value: 'maintenancePrincipalValue',
      type: 'slot',
      require: true,
    },
    {
      label: '养护服务费',
      value: 'maintenanceAmount',
      type: 'number',
      max: 999999999999999,
      formatter: proxy.$fn.TripartiteMethodAsset,
      precision:
        proxy.$store.state.permission.systemConfig.assets_price_precision,
    },
    {
      label: '提醒于',
      value: 'remindTime',
      labelTip: '提醒于任务开始前',
      type: 'slot',
      require: true,
    },
    {
      label: '备注',
      value: 'remark',
      type: 'textarea',
    },
  ],

  rules: {
    type: [{ required: true, message: '请选择养护类型', trigger: 'change' }],
    preAssetName: [
      {
        required: true,
        message: '请选择资产',
        trigger: 'blur',
      },
    ],
    maintenancePrincipalValue: [
      {
        required: true,
        message: '请选择养护负责人',
        trigger: 'blur',
      },
    ],
    nextExecuteDate: [
      {
        required: true,
        message: '请选择计划执行日期',
        trigger: 'blur',
      },
    ],
    remindTime: [
      {
        validator: validateRemind,
        trigger: ['blur', 'change'],
      },
      { required: true, message: '请输入提醒时间', trigger: 'blur' },
    ],
  },
  labelWidth: '120px',
})

// 配件使用过滤相关配置
const filterInfo = reactive({
  query: {
    customizeUserVO: {},
    queryMap: {
      orderId: {
        queryType: 'EQUALS',
        queryCategory: 'AND',
        value: props.id,
      },
    },
  },
  list: [
    { label: '添加配件', type: 'button', event: addMountings },
    { type: 'slot', value: 'removeMountings' },
  ],
})
// 配件使用表格相关
const tableInfo = reactive({
  refresh: 1,
  initCurpage: 1,
  data: [],
  api: null,
  selections: [],
  query: {
    queryParams: {},
    customizeUserVO: {},
    queryMap: {
      orderId: {
        queryType: 'EQUALS',
        queryCategory: 'AND',
        value: props.id,
      },
    },
  },
  fieldList: [],
  handle: {
    fixed: 'right',
    label: '操作',
    width: '50',
    btList: [
      {
        label: '删除',
        event: removeMountings,
        popconfirmText: '删除后将改变数据,是否继续？',
        show: true,
      },
    ],
  },
})
// 养护项目过滤相关配置
const itemsFilterInfo = reactive({
  query: {
    customizeUserVO: {},
    queryMap: {
      orderId: {
        queryType: 'EQUALS',
        queryCategory: 'AND',
        value: props.id,
      },
    },
  },
  list: [
    { label: '添加项目', type: 'button', event: addItem },
    { type: 'slot', value: 'removeItem' },
    { label: '模板添加', type: 'button', event: addTemplate },
  ],
})
// 养护项目表格相关
const itemsTableInfo = reactive({
  refresh: 1,
  initCurpage: 1,
  api: getDeviceMaintenanceTaskProgramAll,
  query: {
    orderId: props.id,
  },
  data: [],
  selections: [],
  // query: {
  //   customizeUserVO: {},
  //   queryMap: {
  //     orderId: {
  //       queryType: "EQUALS",
  //       queryCategory: "AND",
  //       value: props.id,
  //     },
  //   },
  // },
  fieldList: [
    {
      label: '养护部位',
      value: 'maintenanceParts',
      type: 'slot',
      // rules: [
      //   {
      //     required: true,
      //     message: '付款类型',
      //     trigger: 'change',
      //   },
      // ],
    },
    {
      label: '养护内容与要求',
      value: 'contentRequire',
      type: 'slot',
    },
    {
      label: '养护结果',
      value: 'result',
      type: 'slot',
      hidden: true,
    },
    {
      label: '备注',
      value: 'remark',
      type: 'slot',
    },
  ],
  handle: {
    fixed: 'right',
    label: '操作',
    width: '50',
    btList: [
      {
        label: '删除',
        event: removeItem,
        popconfirmText: '删除后将改变数据,是否继续？',
        show: true,
      },
    ],
  },
})

//选择资产资产
const selectAssetInfo = reactive({
  visible: false,
  tableKey: 'repairAddCoreAsset-com.slip.spd.entity.vo.core.CoreAssetVO',
  query: {
    queryMap: {
      // id: {
      //   queryType: "NOT_IN",
      //   queryCategory: "AND",
      //   value: "",
      // },
      status: {
        queryType: 'IN',
        queryCategory: 'AND',
        value: '3',
      },
      assetStatus: {
        queryType: 'IN',
        queryCategory: 'AND',
        value: '1,3',
      },

      isMaintenance: {
        queryType: 'EQUALS',
        queryCategory: 'AND',
        value: 1,
      },
      assetSourceAuth: {
        asTbName: 'core_asset,core_asset',
        columnName: 'use_dept_id,depot_id',
        queryType: 'IN',
        queryCategory: 'AND',
        value: 'assetSourceAuth',
      },
    },
    queryParams: {},
  },
})

const selectUserInfo = reactive({
  visible: false,
  saveEmpty: true,
  query: {
    orgId: '',
    hasAllDept: 1,
  },
})
const selectSupplierInfo = reactive({
  visible: false,
  api: getSupplierPage,
  query: {
    supplierAuth: 'supplierId',
  },
})
//选择配件
const accessoriesInfo = reactive({
  visible: false,
  tableKey:
    'accessoriesArchivesDialog-com.slip.spd.entity.vo.asset.settings.AccessoriesArchivesVO',
  query: {
    id: {
      queryType: 'NOT_IN',
      queryCategory: 'AND',
      value: '',
    },
  },
})
const selectCustomizeTableInfo = ref({
  visible: false,
  api: getDeviceMaintenanceTemplateCustomizeListPage,
  query: {
    deptAuth: {
      asTbName: 'device_maintenance_template',
      columnName: 'dept_id',
      queryType: 'IN',
      queryCategory: 'AND',
      value: 'deptAuth',
    },
  },
  tableKey:
    'deviceMaintenanceTemplateList-com.slip.spd.entity.vo.device.maintenance.template.DeviceMaintenanceTemplateVO',
  defaultObj: {
    name: {
      label: '模板名称',
      value: 'name',
      componentType: 'input',
      show: false,
      hidden: true,
    },
  },
})

const showDialog = computed({
  get() {
    return props.visible
  },
  set(newValue) {
    emit('update:visible', newValue) // 更新父组件visible
  },
})

let obj = {
  price: {
    label: '单价',
    value: 'price',
    componentType: 'price',
    type: 'slot',
    formatter: proxy.$fn.TripartiteMethodAsset,
    show: false,
    hidden: true,
  },
  qty: {
    label: '数量',
    value: 'qty',
    type: 'slot',
    componentType: 'number',
    formatter: proxy.$fn.TripartiteMethodAsset,
    show: false,
    hidden: true,
  },
  preUnitValue: {
    label: '计量单位',
    value: 'preUnitValue',
    componentType: 'input',
    // type: "input",
    show: false,
    hidden: true,
  },
  replaceTime: {
    label: '更换日期',
    value: 'replaceTime',
    componentType: 'input',
    show: false,
    type: 'slot',
    hidden: true,
  },
}
tableInfo.fieldList = Object.values({
  ...proxy.$fn.deepClone(proxy.$fieldfList.FieldList),
  ...obj,
})
// getCustomize();
if (props.id) {
  getMain()
}

onMounted(() => {
  formRefs = [proxy.$refs['itemsTableForm'], formInfo.ref]
  proxy.$nextTick(() => {
    if (!props.id) {
      formInfo.fieldList = formInfo.fieldList.filter(
        (item) => item.value !== 'orderNo'
      )
    }
  })
})

function changePrice(e, row, str) {
  if (str === 'qty') {
    row.sumAmount = proxy.$fn.accMul(e, row.price)
  } else if (str === 'price') {
    row.sumAmount = proxy.$fn.accMul(e, row.qty)
  }
}
function validateUseTime(rule, value, callback) {
  let currentTime = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
  if (value > currentTime) {
    callback(new Error('更换日期不能大于当前时间！'))
  } else {
    callback()
  }
}
//完工图片
function upload(data) {
  formInfo.data.filePathList = data
}
//资产资产
function openAssetWindow() {
  if (!props.id) {
    selectAssetInfo.visible = true
  }
}
function callBackAsset(data) {
  selectAssetInfo.visible = false
  if (data) {
    formInfo.data['preAssetName'] = data.assetName
    formInfo.data['preAssetCode'] = data.assetCode
    formInfo.data['assetCode'] = data.assetCode
    formInfo.data['assetId'] = data.id
    formInfo.data['preStandard'] = data.standard
    if (data.assetStatus === 1) {
      // assetUseDeptVOList
      if(data.assetUseDeptVOList &&  data.assetUseDeptVOList.length) {
        let name = []
        let id = []
        data.assetUseDeptVOList.map(item => {
          name.push(item.useDeptName)
          id.push(item.useDeptId)
        })
        formInfo.data['preUseDeptValue'] = name.join(',')
        // formInfo.data['preUseDeptId'] = id.join(',')
      } else {
        formInfo.data['preUseDeptValue'] = ''
        formInfo.data['preUseDeptId'] = ''
      }
      formInfo.data['depotName'] = ''
      formInfo.data['depotId'] = ''
      showFieldListItem(true, 'preUseDeptValue')
      showFieldListItem(false, 'depotName')
    } else if (data.assetStatus === 3) {
      formInfo.data['depotName'] = data.depotName
      formInfo.data['depotId'] = data.depotId
      formInfo.data['preUseDeptValue'] = ''
      formInfo.data['preUseDeptId'] = ''
      showFieldListItem(false, 'preUseDeptValue')
      showFieldListItem(true, 'depotName')
    }
  } else {
    formInfo.data['preAssetName'] = ''
    formInfo.data['preAssetCode'] = ''
    formInfo.data['assetCode'] = ''
    formInfo.data['assetId'] = ''
    formInfo.data['preUseDeptValue'] = ''
    formInfo.data['preUseDeptId'] = ''
    formInfo.data['preStandard'] = ''
    formInfo.data['depotName'] = ''
    formInfo.data['depotId'] = ''
  }
}

//养护负责人
function openUserWindow() {
  selectUserInfo.visible = true
}
function selectUserCallback(row) {
  if (row) {
    formInfo.data['maintenancePrincipalValue'] = row.name
    formInfo.data['maintenancePrincipal'] = row.id
  } else {
    formInfo.data['maintenancePrincipalValue'] = ''
    formInfo.data['maintenancePrincipal'] = ''
  }
}
//供应商
function openSupplierNameWindow() {
  selectSupplierInfo.visible = true
}
function selectSupplierCallback(row) {
  if (row) {
    formInfo.data['supplierId'] = row.supplierId
    formInfo.data['supplierName'] = row.supplierName
  } else {
    formInfo.data['supplierId'] = ''
    formInfo.data['supplierName'] = ''
  }
}

//添加配件
function addMountings() {
  accessoriesInfo.visible = true
}

//删除配件
function removeMountings(row = undefined) {
  if (row) {
    tableInfo.data = tableInfo.data.filter((item) => item !== row)
  } else {
    tableInfo.data = tableInfo.data.filter((row) => {
      return !tableInfo.selections.includes(row)
    })
  }
}
//选择配件
function changeAccessories(data) {
  if (data.length) {
    data.forEach((item) => {
      let obj = {
        productId: item.id,
        preCommonName: item.commonName,
        preStandard: item.standard,
        preUnitValue: item.unitName,
        ...item,
      }
      tableInfo.data.unshift(obj)
    })
    accessoriesInfo.visible = false
  }
}

//添加养护项目
function addItem() {
  let tableInfo = itemsTableInfo
  let obj = {
    maintenanceParts: '',
    contentRequire: '',
  }
  tableInfo.data.push(obj)
}

//删除养护项目
function removeItem(row = undefined) {
  let tableInfo = itemsTableInfo
  if (row) {
    tableInfo.data = tableInfo.data.filter((item) => item !== row)
  } else {
    proxy
      .$confirm('删除后将改变数据,是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
      .then(() => {
        tableInfo.data = tableInfo.data.filter((row) => {
          return !tableInfo.selections.includes(row)
        })
      })
  }
}
function addTemplate() {
  selectCustomizeTableInfo.value.visible = true
}
function selectCustomizeTableCallback(data) {
  if (data && data.length) {
    const ids = data.map((item) => item.id)
    getDeviceTemplateListByIds({
      idSet: ids
    }).then((res) => {
      itemsTableInfo.data = res.data
    })
  }
}
function tableRowClassName({ row = undefined }) {
  if (row.isChoice) {
    return 'success-row'
  } else {
    return ''
  }
}
function getMountingsUseList() {
  let params = { ...tableInfo.query }
  getDeviceMaintenanceTaskAccessoriesCustomizeListAll(params).then((resp) => {
    if (resp && resp.success) {
      tableInfo.data = resp.data
    }
  })
}

function getItemsList() {
  itemsTableInfo.refresh = Math.random()
}
function showFieldListItem(show, nameValue) {
  let fieldList = formInfo.fieldList
  fieldList.forEach((item) => {
    if (nameValue === item.value) {
      item.show = show
    }
  })
}
function getMain() {
  getDeviceMaintenanceTaskById(props.id).then((resp) => {
    if (resp && resp.success) {
      formInfo.data = resp.data
      itemsTableInfo.data = resp.data.deviceMaintenanceTaskProgramVOList
      if (resp.data.assetStatus === 1) {
        showFieldListItem(true, 'preUseDeptValue')
        showFieldListItem(false, 'depotName')
      } else if (resp.data.assetStatus === 3) {
        showFieldListItem(false, 'preUseDeptValue')
        showFieldListItem(true, 'depotName')
      }
    }
  })
  filterInfo.query.queryMap.orderId.value = props.id
  getItemsList()
}
function getCustomize() {
  let param = {
    tableKey:
      'deviceMaintenanceTaskAddAccessoriesList-com.slip.spd.entity.vo.asset.settings.AccessoriesArchivesVO',
  }
  tableInfo.isSysGroup = false
  getCustomizeSetting(param).then((res) => {
    if (res && res.success) {
      let data = res.data
      filterInfo.query.customizeUserVO = res.data

      tableInfo.query.customizeUserVO = res.data
      console.log(
        tableInfo.query.customizeUserVO,
        'tableInfo.query.customizeUserVO'
      )
      tableInfo.fieldList = proxy.$fn.setFieldList(
        tableInfo.fieldList,
        data.detail
      )
      for (let key in data.detail) {
        if (data.detail[key].sysGroupLevel > 0) {
          tableInfo.isSysGroup = true
        }
      }
      tableInfo.api = getDeviceMaintenanceTaskAccessoriesCustomizeListAll
    }
    if (props.id) {
      getMain()
    }
  })
}

// 触发事件
function handleEvent(event, data) {
  switch (event) {
    case 'tableCheck':
      tableInfo.selections = data
      break
  }
}

function handleEventItems(event, data) {
  switch (event) {
    case 'tableCheck':
      itemsTableInfo.selections = data
      break
  }
}

//保存
function save() {
  proxy.$fn.checkForm(formRefs).then(() => {
    const data = {
      ...formInfo.data,
    }
    //养护项目不能为空
    if (itemsTableInfo.data == null || itemsTableInfo.data.length < 1) {
      ElMessage.warning({
        message: '请添加养护项目',
        show: true,
        duration: 3000,
      })
      return
    }
    data.deviceMaintenanceTaskProgramVOList = itemsTableInfo.data //养护项目
    data.deviceMaintenanceTaskAccessoriesVOList = tableInfo.data //配件
    data.status = '1'
    const api = props.id
      ? updateByIdWhenStatusNotStart
      : createDeviceMaintenanceTask
    api(data).then((resp) => {
      if (resp && resp.success) {
        showDialog.value = false
        emit('returnModify')
      } else {
        ElMessage.error({
          message: resp.data.msg,
          duration: 3000,
          showClose: true,
        })
      }
    })
  })
}
</script>

<style scoped>
.form-date {
  width: 50%;
  display: inline-block;
}
.form-date-type {
  width: 50%;
  /* display: inline-block; */
  float: right;
}
.form-input {
  margin: 15px auto;
}
.i-more-disabled {
  cursor: not-allowed;
}
.i-more {
  background-color: #ffffff;
  cursor: pointer;
  height: 26px;
}
</style>
